//
//  TestTableViewWC.m
//  sandbox
//
//  Created by 杨岑 on 5/6/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "TestTableViewWC.h"
#import "TestTableViewDataSource.h"


@interface TestTableViewWC ()
@property (strong) IBOutlet TestTableViewDataSource *testDataSource;
@property (weak) IBOutlet NSTableColumn *valueColumn;
@end

@implementation TestTableViewWC


- (void)awakeFromNib
{
    self.testDataSource.count = 10;
}

- (IBAction)removeRows_click:(id)sender {
    @try {
        NSIndexSet* toRemove = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(3, 3)];
        [self.tableView removeRowsAtIndexes:toRemove withAnimation:YES];
    }
    @catch (NSException *exception) {
        NSLog(@"%@", exception);
    }
    @finally {
        
    }
}

- (IBAction)insertRows_click:(id)sender {
    NSIndexSet* toInsert = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(3, 3)];
    [self.tableView insertRowsAtIndexes:toInsert withAnimation:YES];
}

- (IBAction)reload_click:(id)sender {
    self.testDataSource.count = [self.input.stringValue integerValue];
    [self.tableView noteNumberOfRowsChanged];
    [self reloadList];
    NSLog(@"Reload done");
}

- (IBAction)test_click:(id)sender {
    
}

- (IBAction)rowSize_click:(id)sender {
    NSMatrix* sizes = sender;
    switch (sizes.selectedColumn) {
        case 0:
            self.tableView.rowSizeStyle = NSTableViewRowSizeStyleDefault;
            break;
            
        case 1:
            self.tableView.rowSizeStyle = NSTableViewRowSizeStyleSmall;
            break;

        case 2:
            self.tableView.rowSizeStyle = NSTableViewRowSizeStyleMedium;
            break;

        case 3:
            self.tableView.rowSizeStyle = NSTableViewRowSizeStyleLarge;
            break;

        default:
            break;
    }
}

- (void)reloadList
{
    NSIndexSet* rows = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.testDataSource.count)];
    NSIndexSet* cols = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)];
    [self.tableView reloadDataForRowIndexes:rows columnIndexes:cols];
}


@end
